﻿var EmptyGuid = '00000000-0000-0000-0000-000000000000';
function RefreshPage(arg) {
    //        Refresh();

    var type = parseInt(arg); ////本页刷新变量为true，审核页面返回1
    if (type == 1) {
        top.ChildDialogCallBack = "Refresh";
        top.ChildDialogClose(1);

    } else {
        Refresh();
    }
}
//begin 2013-12-4
//取得上传验证图片列表
function GetCheckImg() {
    // sysCode = "";
    funcCode = "";
    $("#divImages img[checkempty='yes']").each(function () {
        //  sysCode += $(this).attr("syscode") + ",";
        funcCode += $(this).attr("FuncCode") + ",";
    });
    return funcCode;
}
///取得未上传图片名
function GetCheckImgTitle(code) {
    var result = "";
    if (code.length > 0) {
        $("#divImages img[FuncCode='" + code + "']").each(function () {
            result = $(this).attr("title");
        });
    }
    return result;
}
//end

$(function () {
    /*地区控件在IE7下移动问题解决*/
    $("#RAD_SPLITTER_PANE_CONTENT_rpRight").css("position", "relative");

    $("#save").click(function () {
        var dataValid = CheckControlValid("save");
        if (!dataValid) {
            return false;
        }
        //取得验证图片begin
        var corpUserGuid = $("#ContentPlaceHolder1_hdnCorpUserguid").val();
        var funcCode = GetCheckImg();
        //end
        var dataStr = GetData("save");
        //$.getJSON方法为get传值，如果数据量过大则会失效，使用post传值则会避免此问题
        $.post("../Handlers/EnterpriseCorpInfoHandler.ashx",
            { "action": "CorpSafeAdd", "data": dataStr, "funcCode": funcCode, "corpGuid": corpUserGuid, "rand": Math.random() },
            function (data) {
                var result = eval(data);
                if (result.Result == true) {
                    radalert(result.Message, 300, 150, '提示', RefreshPage);
                    return;
                }
                else {
                    //未上传的图片
                    if (data.Message == "img") {
                        var text = GetCheckImgTitle(data.ReturnValue);
                        $.ligerDialog.alert(text + "必须上传！");
                        return false;
                    }
                    $.ligerDialog.alert(result.Message);
                    return;
                }
            },
            "json"
        );
    });
    $("#Post").click(function () {
        //$.getJSON方法为get传值，如果数据量过大则会失效，使用post传值则会避免此问题
        radconfirm('确定上报企业信息，上报后信息不可修改？', Post, 300, 150, null, '提示');
        return false;
        function Post(arg) {

            if (arg) {
                ////先执行一次保存方法，可能填写完数据直接点击上报，此时数据尚未保存
                var dataStr = GetData("Post");
                $.ajax({
                    data: { "action": "CorpSafeAdd", "data": dataStr, "rand": Math.random() },
                    url: "../Handlers/EnterpriseCorpInfoHandler.ashx",
                    async: false, ////同步调用
                    type: "post",
                    dataType: "json",
                    success: function (data) {
                        if (data.Result == true) {
                            //取得验证图片begin
                            var corpUserGuid = $("#ContentPlaceHolder1_hdnCorpUserguid").val();
                            var funcCode = GetCheckImg();
                            //end
                            $.ajax({
                                data: { "action": "CorpSafePost", "funcCode": funcCode, "corpGuid": corpUserGuid, "rand": Math.random() },
                                url: "../Handlers/EnterpriseCorpInfoHandler.ashx",
                                async: false,
                                type: "get",
                                dataType: "json",
                                success: function (data) {
                                    if (data.Result == true) {
                                        radalert(data.Message, 300, 150, '提示', RefreshPage);
                                        return;
                                    }
                                    else {//未上传的图片
                                        if (data.Message == "img") {
                                            var text = GetCheckImgTitle(data.ReturnValue);
                                            $.ligerDialog.alert(text + "必须上传！");
                                            return false;
                                        }
                                        $.ligerDialog.alert(data.Message);
                                        return;
                                    }
                                }
                            });
                        }
                        else {

                            $.ligerDialog.alert(data.Message);
                            return;
                        }
                    }
                }
                );
            }
        }
    }
    );
    $("#CancelPost").click(function () {
        //$.getJSON方法为get传值，如果数据量过大则会失效，使用post传值则会避免此问题
        radconfirm('确定取消上报信息？', Post, 300, 150, null, '提示');
        return false;
        function Post(arg) {
            $.ajax({
                data: { "action": "CancelPost", "rand": Math.random() },
                url: "../Handlers/EnterpriseCorpInfoHandler.ashx",
                async: false,
                type: "get",
                dataType: "json",
                success: function (data) {
                    if (data.Result == true) {
                        radalert(data.Message, 300, 150, '提示', RefreshPage);
                        return;
                    }
                    else {
                        $.ligerDialog.alert(data.Message);
                        return;
                    }
                }
            });
        }
    }
    );
    $("#Audit").click(function () {
        var corpUserGuid = $("#ContentPlaceHolder1_hdnCorpUserguid").val();
        $.ligerDialog.open({ url: "../Enterprise/EnterpriseSafeCertAudit.aspx?corpGuid=" + corpUserGuid + "&rand=" + Math.random(), width: 820, height: 420, title: '', isResize: true });

        return false;
    }
    );

    /*扫描件上传空间事件*/
    $(".corpImages[except!='except'] button").each(function () {
        var corpUserGuid = $("#ContentPlaceHolder1_hdnCorpUserguid").val();
        var sysCode = $(this).attr("sysCode");
        var funcCode = $(this).attr("FuncCode");
        $(this).click(function () {
            // window.radopen("../Person/PersonUploadFile.aspx?filename=" + corpUserGuid + "&FuncCode=" + funcCode, "radWindowUpload");
            $.ligerDialog.open({ url: "../UserControl/FileUploadList.aspx?filename=" + corpUserGuid + "&FuncCode=" + funcCode, width: 650, height: 570, title: '', isResize: true });
            return false;
        });
    });

    BindImage();

    var editModel = $("#ContentPlaceHolder1_hdnEditModel").val();
    var CurrentEmbranchEditModel = $("#ContentPlaceHolder1_hdnCurrentEmbranchEditModel").val();
    if (editModel == "1") {
        SetControlEditById(editModel, "tb_Corp_Companyinfo");
        SetControlEditById(editModel, "ContentPlaceHolder1_divSecurityCode");

        $("#CorpQualityAdd").hide();
        $("#CorpQualityEdit").hide();
        $("#CorpQualityDel").hide();
        ////不可编辑则提供查看功能
        //        $(".corpImages button").each(function () {
        //            $(this).hide();
        //        });
        ////不可编辑则提供查看功能2013-12-4
        var editPicModel = $("#ContentPlaceHolder1_hdnCanUploadPic").val();
        if (editPicModel == "0") {
            $(".corpImages button").each(function () {
                $(this).hide();
            });
        } //end
    }

    if (CurrentEmbranchEditModel == "1") {
        SetControlEditById(editModel, "ContentPlaceHolder1_divEmbranchment");
    }
    else {
        //外地准入扫描件可上传
        $(".corpImages button[funccode='CorpWDZR']").show();
    }
    $("#ContentPlaceHolder1_txtBussinessArea,#ContentPlaceHolder1_txtIntroduction").keyup(function () {
        TextMaxLength(this, 500);
    })
    $(".input_mm i a[except!='except']").each(function () {
        var corpUserGuid = $("#ContentPlaceHolder1_hdnCorpUserguid").val();
        var imgObj = $(this);
        var sysCode = imgObj.attr("sysCode");
        var funcCode = imgObj.attr("FuncCode");
        imgObj.click(function () {
            top.$.ligerDialog.open({ url: "Enterprise/UploadFileShowList.aspx?filename=" + corpUserGuid + "&funcCode=" + funcCode + "&sysCode=" + sysCode + "&fileType=.jpg", width: 820, height: 650, title: '', isResize: true, buttons: [{ text: '关闭', onclick: function (item, dialog) { dialog.close(); } }] });
            return false;
        }
        );
    }
    );
    $(".tishi_tt_t cite").addClass("pointer");
    $(".tishi_tt_t cite").click(function () {
        $("#PromptMain").toggle();
    }
    );
}
);

function GetIsMain(isMain) {
    var title = "否";
    if (isMain != null && isMain == true) {
        title = "是";
    }
    return title;
}

function GetIdTypeTitle(idType) {
    switch (idType) {
        case "1":
            return "身份证";
        case "2":
            return "军官证";
        case "3":
            return "护照";
        default: return "";
    }
}


function GetString(obj) {
    if (obj == null || obj == undefined) {
        return '';
    }
    return obj;
}

Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(),    //day
        "h+": this.getHours(),   //hour
        "m+": this.getMinutes(), //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
        "S": this.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
 (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o) if (new RegExp("(" + k + ")").test(format))
        format = format.replace(RegExp.$1,
 RegExp.$1.length == 1 ? o[k] :
 ("00" + o[k]).substr(("" + o[k]).length));
    return format;
}

function DateFormat(obj) {
    if (obj == null || obj == undefined || obj == '') {
        return "";
    }
    try {
        var objDate = new Date(obj);
        return objDate.format("yyyy-M-dd");
    }
    catch (ex) {
        return "";
    }
}
function OnClientCloseImg(args) {
    var arg = args;
    if (arg) {
        if (arg.Result == 1) {
            return;
        }
        AfterUpload();
    }
}
function AfterUpload() {
    BindImage();
}

function BindImage() {
    var corpUserGuid = $("#ContentPlaceHolder1_hdnCorpUserguid").val();
    //排除主项资质的绑定[except!='except']
    $(".corpImages[except!='except'] img").each(function () {
        var imgObj = $(this);
        var sysCode = imgObj.attr("sysCode");
        var funcCode = imgObj.attr("FuncCode");
        imgObj.attr("src", "../Handlers/GetFileHandler.ashx?fileName=" + corpUserGuid + ".jpg&sysCode=" + sysCode + "&funcCode=" + funcCode + "&rand=" + Math.random());
        imgObj.show();
        imgObj.click(function () {
            top.$.ligerDialog.open({ url: "Enterprise/UploadFileShowList.aspx?filename=" + corpUserGuid + "&funcCode=" + funcCode + "&sysCode=" + sysCode + "&fileType=.jpg", width: 820, height: 650, title: '', isResize: true, buttons: [{ text: '关闭', onclick: function (item, dialog) { dialog.close(); } }] });
            return false;
        }
        );
    }
);
}

function TextMaxLength(control, maxlength) {
    var text = control.value;
    if (text.length > maxlength) {
        control.value = text.substring(0, maxlength);
        alert("超出了最大字数");
    }
}

function showPromptDetail() {
    $("#PromptMain").toggle();
}

/*打开添加窗口*/
function ShowUpForm(u, w, h, win) {
    win = win || this;
    $.ligerDialog.open({ url: u, width: w, height: h, title: '', buttons: [{ text: '关闭', onclick: function (item, dialog) { dialog.close(); } }] });
    win.ChildDialogWin = this;
    return false;
}

function Refresh() {
    window.location.reload();
}